using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using System;
using System.Collections;
using System.Collections.Generic;

using zijian666.DI;

namespace UnitTests;

[TestClass]
public class 各种类型转换测试
{
    [TestMethod]
    public void Test()
    {
        var services = new ServiceCollection()
            .AddSingleton<MyService>()
            .AddSingleton<MyAutowired>()
            .AddAutowired()
            .BuildServiceProvider();

        var my = services.GetService<MyAutowired>();

        foreach (var field in my.GetType().GetFields())
        {
            Console.Write($"{field.Name}  ----> ");
            var value = field.GetValue(my);
            Assert.IsNotNull(value);
            if (value is IEnumerable arr)
            {
                Assert.IsTrue(arr.GetEnumerator().MoveNext());
            }
            Console.WriteLine("ok");
        }

    }


    interface IService
    {

    }
    class MyService : IService
    {

    }

    class MyAutowired
    {
        [Autowired]
        public MyService[] field_1;
        [Autowired(serviceType: typeof(MyService))]
        public object[] field_2;
        [Autowired(serviceType: typeof(MyService))]
        public IService[] field_3;
        [Autowired(serviceType: typeof(MyService))]
        public IEnumerable field_4;
        [Autowired(serviceType: typeof(MyService))]
        public IList field_5;
        [Autowired(serviceType: typeof(MyService))]
        public ArrayList field_6;
        [Autowired]
        public IEnumerable<MyService> field_7;
        [Autowired]
        public IList<MyService> field_8;
        [Autowired]
        public List<MyService> field_9;
        [Autowired(serviceType: typeof(MyService))]
        public IEnumerable<object> field_10;
        [Autowired(serviceType: typeof(MyService))]
        public IList<object> field_11;
        [Autowired(serviceType: typeof(MyService))]
        public List<object> field_12;
        [Autowired(serviceType: typeof(MyService))]
        public IEnumerable<IService> field_13;
        [Autowired(serviceType: typeof(MyService))]
        public IList<IService> field_14;
        [Autowired(serviceType: typeof(MyService))]
        public List<IService> field_15;
        [Autowired(serviceType: typeof(MyService))]
        public object field_17;
        [Autowired(serviceType: typeof(MyService))]
        public IService field_18;
        [Autowired]
        public MyService field_19;


        [Autowired(serviceType: typeof(IEnumerable<MyService>))]
        public ArrayList field_20;
        [Autowired(serviceType: typeof(MyService))]
        public IEnumerable<MyService> field_21;
    }
}
